import {
  FilesInterceptor,
  MemoryStorageFile,
  UploadedFiles,
} from '@blazity/nest-file-fastify';
import { Public } from '@libs/common/decorator';
import { IndexInterceptor } from '@libs/common/interceptors';
import {
  Body,
  Controller,
  Get,
  Post,
  Query,
  UseInterceptors,
} from '@nestjs/common';

import {
  CreatePerformanceDto,
  DeletePerformanceDto,
  FindPerformanceDto,
  ImportPerformanceDto,
  IndexPerformanceDto,
  ShowPerformanceDto,
  UpdatePerformanceDto,
} from './dto/performance.dto';
import { PerformanceService } from './performance.service';

@Controller('performance')
export class PerformanceController {
  constructor(private readonly performanceService: PerformanceService) {}

  @Post('index')
  @UseInterceptors(new IndexInterceptor())
  index(@Body() dto: IndexPerformanceDto) {
    return this.performanceService.index(dto);
  }

  @Post('show')
  show(@Body() dto: ShowPerformanceDto) {
    return this.performanceService.show(dto);
  }

  @Get('find')
  find(@Query() dto: FindPerformanceDto) {
    return this.performanceService.find(dto);
  }

  @Post('delete')
  delete(@Body() dto: DeletePerformanceDto) {
    this.performanceService.delete(dto);
  }

  @Post('create')
  create(@Body() dto: CreatePerformanceDto) {
    this.performanceService.create(dto);
  }

  @Post('update')
  update(@Body() dto: UpdatePerformanceDto) {
    this.performanceService.update(dto);
  }

  @Post('import')
  @UseInterceptors(FilesInterceptor('files', 99))
  async import(
    @Body() dto: ImportPerformanceDto,
    @UploadedFiles()
    files: MemoryStorageFile[],
  ) {
    return this.performanceService.import(dto.date, files);
  }

  // @Post('export')
  // export(@Body() dto: ExportPerformanceDto) {}

  // @Post('switch')
  // switch(dto: SwitchPerformanceDto) {
  //   return this.performanceService.switch(dto.id, dto.status);
  // }
}
